package it.irondev.appturismo.dao;

import it.irondev.appturismo.dao.example.RouteExample;
import it.irondev.appturismo.dao.provider.RouteSqlProvider;
import it.irondev.appturismo.entity.Difficulty;
import it.irondev.appturismo.entity.Language;
import it.irondev.appturismo.entity.Route;
import it.irondev.appturismo.entity.Routestages;
import it.irondev.appturismo.entity.RoutestagesExample;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface RouteMapper {
    @SelectProvider(type=RouteSqlProvider.class, method="countByExample")
    int countByExample(RouteExample example);

    @DeleteProvider(type=RouteSqlProvider.class, method="deleteByExample")
    int deleteByExample(RouteExample example);

    @Delete({
        "delete from Route",
        "where idRoute = #{idroute,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer idroute);

    @Insert({
        "insert into Route (idRoute, name, ",
        "description, duration, ",
        "difficulty, email, ",
        "language, gallery)",
        "values (#{idroute,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, ",
        "#{description,jdbcType=VARCHAR}, #{duration,jdbcType=VARCHAR}, ",
        "#{difficulty.iddifficulty,jdbcType=INTEGER}, #{email,jdbcType=VARCHAR}, ",
        "#{language.idlanguage,jdbcType=INTEGER}, #{gallery,jdbcType=INTEGER})"
    })
	@Options(useGeneratedKeys = true, keyProperty="idroute")
    int insert(Route record);

    @InsertProvider(type=RouteSqlProvider.class, method="insertSelective")
    int insertSelective(Route record);

    @SelectProvider(type=RouteSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="idRoute", property="idroute", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="description", property="description", jdbcType=JdbcType.VARCHAR),
        @Result(column="duration", property="duration", jdbcType=JdbcType.VARCHAR),
        @Result(column="email", property="email", jdbcType=JdbcType.VARCHAR),
        @Result(column="difficulty", property="difficulty",  javaType=Difficulty.class, one=@One(select="it.irondev.appturismo.dao.DifficultyMapper.selectByPrimaryKey")),
		@Result(column="language", property="language", javaType=Language.class, one=@One(select="it.irondev.appturismo.dao.LanguageMapper.selectByPrimaryKey")),
		@Result(column="idRoute",property="stages", javaType=List.class, many=@Many(select="it.irondev.appturismo.dao.RoutestagesMapper.selectByRouteId")),
		@Result(column="gallery", property="gallery", jdbcType=JdbcType.INTEGER)
    })
    List<Route> selectByExample(RouteExample example);

    @Select({
        "select",
        "idRoute, name, description, duration, difficulty, email, language, gallery",
        "from Route",
        "where idRoute = #{idroute,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="idRoute", property="idroute", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="description", property="description", jdbcType=JdbcType.VARCHAR),
        @Result(column="duration", property="duration", jdbcType=JdbcType.VARCHAR),
        @Result(column="email", property="email", jdbcType=JdbcType.VARCHAR),
        @Result(column="difficulty", property="difficulty",  javaType=Difficulty.class, one=@One(select="it.irondev.appturismo.dao.DifficultyMapper.selectByPrimaryKey")),
		@Result(column="language", property="language", javaType=Language.class, one=@One(select="it.irondev.appturismo.dao.LanguageMapper.selectByPrimaryKey")),
		@Result(column="idRoute",property="stages", javaType=List.class, many=@Many(select="it.irondev.appturismo.dao.RoutestagesMapper.selectByRouteId")),
		@Result(column="gallery", property="gallery", jdbcType=JdbcType.INTEGER)
    })
    Route selectByPrimaryKey(Integer idroute);

    @UpdateProvider(type=RouteSqlProvider.class, method="updateByExampleSelective")
    int updateByExampleSelective(@Param("record") Route record, @Param("example") RouteExample example);

    @UpdateProvider(type=RouteSqlProvider.class, method="updateByExample")
    int updateByExample(@Param("record") Route record, @Param("example") RouteExample example);

    @UpdateProvider(type=RouteSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Route record);

    @Update({
        "update Route",
        "set name = #{name,jdbcType=VARCHAR},",
          "description = #{description,jdbcType=VARCHAR},",
          "duration = #{duration,jdbcType=VARCHAR},",
          "difficulty = #{difficulty.iddifficulty,jdbcType=INTEGER},",
          "email = #{email,jdbcType=VARCHAR},",
          "language = #{language.idlanguage,jdbcType=INTEGER},",
          "gallery = #{gallery,jdbcType=INTEGER}",
        "where idRoute = #{idroute,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Route record);

    
}